package com.furongji.education.controller.api;

import com.furongji.common.result.Result;
import com.furongji.education.service.PayService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;


/**
 * <p>
 * 支付表 前端控制器
 * </p>
 *
 * @author furongji
 * @since 2025-05-29
 */
@Tag(name = "支付管理")
@RestController
@RequestMapping("/api/orders")
@RequiredArgsConstructor
public class PayApiController {

    private final PayService payService;

    @Operation(summary = "生成支付宝二维码")
    @PostMapping("/pay/{orderId}")
    public Result pay(@PathVariable String orderId) throws Exception {
        System.err.println("开始订单支付...");
        String qrCode = payService.createQRCode(orderId);
        return Result.success(qrCode);
    }

    @Operation(summary = "支付宝回调地址")
    @PostMapping("/notify")
    public String payNotify(HttpServletRequest request) throws Exception {
        System.err.println("开始支付宝回调...");
        String result = payService.handleAlipayNotify(request);
        return result;
    }
}
